/*
 *	HelpPanelControl.m
 *
 *		by  Takeshi Ogihara (ogihara@seg.kobe-u.ac.jp)
 */

#import "HelpPanelControl.h"
#import "strfunc.h"

@implementation HelpPanelControl

static char *helpindex[] = {
	"HelpDoc.rtf", "HelpInfo.rtf", "Copyright.rtf"
};

- makeKeyAndOrderFront:sender
{
	if (helpPanel == nil) {
		[NXApp loadNibSection:"HelpPanel.nib" owner:self];
		curtag = -1;
		[self readHelp: 0];
	}
	[helpPanel makeKeyAndOrderFront:sender];
	return self;
}

- selectHelp:sender
{
	int tag = [sender selectedTag];
	if (tag != curtag)    
		[self readHelp: tag];
	return self;
}

- readHelp: (int) helpid
{
	int n;
	char buf[256];
	char *const *lang;
	NXStream *s;


	n = dircopy(buf, NXArgv[0], YES);
	if (n < 0 || (lang = [NXApp systemLanguages]) == NULL) {
		curtag = 0;
		return self;
	}
	for ( ; *lang; lang++) {
		sprintf(&buf[n], "%s.lproj/%s", *lang, helpindex[helpid]);
		s = NXMapFile(buf, NX_READONLY);
		if (s) {
			[helpText readRichText:s];
			NXCloseMemory(s, NX_FREEBUFFER);
			curtag = helpid;
			return self;
		}
	}
	curtag = 0;
	return self;
}

@end
